﻿using System;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Reflection;
using System.Windows.Resources;

namespace WPAChess
{
    public class MiniChessBoard : UserControl
    {
        private Canvas graphic;
        public MiniChessBoard(String resourceName)
        {
            StreamResourceInfo res = Application.GetResourceStream(new Uri("WPAChess;component/MiniChessBoards/" + resourceName, UriKind.Relative));
            StreamReader reader = new StreamReader(res.Stream);

            this.graphic = (Canvas)XamlReader.Load(reader.ReadToEnd());
            this.Content = this.graphic;
        }
    }

    public class MiniChessBoardFactory
    {
        private static readonly string[] miniChessBoardName = new string[] { null, "Standard.xaml", "DColor1.xaml", "DColor2.xaml", "DColor3.xaml" };
        public MiniChessBoard CreateMiniChessBoard(int type)
        {
            string boardName = MiniChessBoardFactory.miniChessBoardName[type & 0xF];
            if (boardName != null)
            {
                return new MiniChessBoard(boardName);
            }
            return null;
        } 
    }
}
